<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>用户增加</title>
<link rel="stylesheet" href="<%=basePath%>res/wzw/layui/css/layui.css"
	media="all">
<style type="text/css">
#goodsImg {
	position: relative;
	left: 110px;
}
</style>
</head>
<body>

	<fieldset class="layui-elem-field layui-field-title"
		style="margin-top: 20px;">
		<legend>用户修改列表</legend>
	</fieldset>

	<form class="layui-form" action="<%=basePath%>manager/manUpdate.action"
		method="post">
		<input type="hidden" id="manId" name="man_id">
		<input type="hidden" id="stId" name="st_id">
		<div class="layui-form-item">
			<label class="layui-form-label">用户名称</label>
			<div class="layui-input-block">
				<input type="text" name="man_user" id="manUser" lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input"
					maxlength="20">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">用户密码</label>
			<div class="layui-input-block">
				<input type="password" name="man_pwd" id="manPwd"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="20">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">用户电话</label>
			<div class="layui-input-block">
				<input onblur="phone()" type="text" name="man_phone" id="manPhone"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">身份证号</label>
			<div class="layui-input-block">
				<input onblur="card()" type="text" name="man_cardid" id="manCardid"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">是否有效</label>
			<div class="layui-input-block">
				<select name="isva" id="isva" required lay-verify="required"
					autocomplete="off" class="layui-input">
					<option></option>
					<option value="0">无效</option>
					<option value="1">有效</option>
				</select>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">用户备注</label>
			<div class="layui-input-block">
				<input type="text" name="man_remark" id="manRemark"
					lay-verify="required" placeholder="请输入" autocomplete="off"
					class="layui-input" maxlength="20">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">赋予角色</label>
			<div id="ehyRole"></div>
		</div>
		<div id="one"></div>
		<input type="hidden" id="str" name="str" />
		<!-- 提交重置 -->
		<div class="layui-form-item">
			<div class="layui-input-block">
				<input onclick="aa()" type="submit" class="layui-btn" lay-submit=""
					lay-filter="manUpdate" value="立即提交">
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
		<!-- <input type="button" onclick="aa()"> -->
	</form>

	<script src="<%=basePath%>res/wzw/layui/layui.js"></script>
	<script type="text/javascript" src="res/wzw/js/jquery.min.1.6.4.js"></script>
	<script src="<%=basePath%>js/jquery-1.10.2.js"></script>
	<script>
//赋值到INPUT
function aa(){
	var bb="";
	var temp="";
	var a=document.getElementsByName("ro");
	//alert(a.length);
	for(var i=0;i<a.length; i++){
		if(a[i].checked){
			temp=a[i].value;
			if(bb==""){
				bb=temp;
			}else{
				bb=bb+","+temp;
			}
		}
	}
	// alert(bb);
	$("#str").val(bb);
}

function phone(){
    var phone = document.getElementById('manPhone').value;
    if(!(/^1[34578]\d{9}$/.test(phone))){
       /* alert("手机号码有误，请重新填写"); */
       $("#manPhone").attr("placeholder","手机号码格式不正确");
       document.getElementById('manPhone').value="";
       return false;
    }
}

function card(){ 
	// 身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X 
	var card = document.getElementById('manCardid').value;
	if(!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(card))){ 
		$("#manCardid").attr("placeholder","身份证格式不正确");
	    document.getElementById('manCardid').value="";
		return false; 
	} 
}

layui.use('form', function(){
  var form = layui.form
  ,layer = layui.layer
  ,$ = layui.$;
  form.on('submit(manUpdate)',function(){
	  parent.location.reload(); // 父页面刷新
  });
  
  //获得角色
  var url = "<%=basePath%>role/findRole";
	$.post(url,null,function(data){
		data = data.data;
		for(var i=0;i<data.length;i++){
			$("#ehyRole").append("<input type='checkbox' value="+data[i].role_id+" name='ro' title="+data[i].role_name+">");
		}
		$.post("<%=basePath%>manager/findManagerRole",{"manId":$("#manId").val()},function(data){
			//data = data.data;
			var a=document.getElementsByName("ro");
			for(var i=0;i<data.length;i++){
				//alert(data[i].roleId);
				//$("#one").append("<input type='text'  value="+data[i].roleId+" name='rr' title="+data[i].roleId+">");
				for(var j=0;j<a.length; j++){
					if(data[i].role_id==a[j].value){
						a[j].checked=true;
					}
				}
			}
			//form表单重新渲染
			form.render();
		},dataType="JSON");
		//form表单重新渲染
		form.render();
	},dataType="JSON");
  
});
</script>

</body>
</html>